package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入借阅的书名:");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int count = bookList.getUseSize();
        int i = 0;
        for (i = 0; i < count; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name)){
                if (book.getBorrow() == false){
                    //改borrow的值
                    book.setBorrow(true);
                    System.out.println("借阅成功");
                }else {
                    System.out.println(name+"已被借出");
                }
                return;
            }
        }
        if (i == count){
            System.out.println("未找到"+name+"这本书");
        }
    }
}
